    program add_util2
    character*6 tick(2900000),ticker
    character*8 cusip(2900000),fcusip(6000),tcusp,cusp
    character*9 retrn,price
    integer(kind=8) nshrs(2900000),nvalue(2900000),numshrs,jvalue,ivol
      dimension iastid(2900000),idate(2900000),util(2900000),ifast(55000),ibg(55000)
      open(unit=10,file='e:\FIS\util_201401_201403_rep.txt')
!      open(unit=11,file='e:\FIS_covid\crsp_sorted_fees_201401_201403.txt')
!      open(unit=99,file='e:\FIS_covid\crsp_util_sorted_fees_201401_201403.txt')
      open(unit=11,file='e:\FIS\crsp_sorted_fees_201401_201403_rep.txt')
      open(unit=99,file='e:\FIS\crsp_util_sorted_fees_201401_201403_rep.txt')
      np=0
      lperm=-1
      i=0
1     i=i+1
2     read(10,1000,end=10)iastid(i),idate(i),cusip(i),tick(i),util(i),nshrs(i),nvalue(i)
1000  format(1x,i8,1x,i8,1x,a9,1x,a6,1x,f6.2,2(1x,i13))      
      if(iastid(i).eq.lastid) go to 1
      np=np+1
      ifast(np)=iastid(i)
      ibg(np)=i
      lastid=iastid(i)
      write(6,6000)np,ifast(np)
6000  format(1x,i5,1x,i8)      
      go to 1
10    icnt=i-1
      write(6,6001)icnt
6001  format(1x,i7)
      lstid=1
100   read(11,1100,end=900)jast,jdate,cusp,ticker,itickt,numshrs,jvalue,age,favg,fmax,fmin,fstd,iperm,idate2,tcusp,price,ivol,retrn,ishrout,vwret      
      write(6,1100)jast,jdate,cusp,ticker,itickt,numshrs,jvalue,age,favg,fmax,fmin,fstd,iperm,idate2,tcusp,price,ivol,retrn,ishrout,vwret      
!1100  format(2(1x,i8),1x,a8,2x,a6,4x,i9,2(1x,i14),5(1x,f11.4),1x,i5,1x,i8,1x,a8,1x,f9.2,1x,i9,1x,a9,1x,i8,1x,f9.6)   
1100 format(2(1x,i8),1x,a8,2x,a6,4x,i9,2(1x,i14),5(1x,f11.4),1x,i5,1x,i8,1x,a8,1x,a9,1x,i10,1x,a9,1x,i9,1x,f9.6)  
!    new
      if(retrn(3:3).ne.'.') go to 100
      if(price.eq.'#########') price='    -0.00'    
      if(jast.eq.lstid) go to 125
      lstid=jast
      j=0
105   j=j+1
      if(j.gt.np) go to 100
      if(jast.eq.ifast(j)) go to 125
      go to 105
125   ii=ibg(j)-1
      if(j.gt.np) go to 100
130   ii=ii+1
      if(jast.ne.iastid(ii)) go to 100
      if(jdate.ne.idate(ii)) go to 130
      write(99,9900)jast,jdate,cusp,ticker,itickt,numshrs,jvalue,age,favg,fmax,fmin,fstd,iperm,price,ivol,retrn,ishrout,vwret,iastid(ii),idate(ii),cusip(ii),util(ii),nshrs(ii),nvalue(ii)      
!9900  format(2(1x,i8),1x,a8,2x,a6,4x,i9,2(1x,i14),5(1x,f11.4),1x,i5,1x,f9.2,1x,i9,1x,a9,1x,i8,1x,f9.6,2(1x,i8),1x,a9,1x,f6.2,2(1x,i13))   
9900  format(2(1x,i8),1x,a8,2x,a6,4x,i9,2(1x,i14),5(1x,f11.4),1x,i5,1x,a9,1x,i10,1x,a9,1x,i9,1x,f9.6,2(1x,i8),1x,a9,1x,f6.2,2(1x,i13))   

!      write(99,9900)jast,jdate,cusp,ticker,itickt,nshrs,jvalue,age,favg,fmax,fmin,fstd,iperm(ii),idate(ii),cusip(ii),price(ii),ivol(ii),retrn(ii),ishrout(ii),vwret(ii)      
!9900  format(2(1x,i8),1x,a8,2x,a6,4x,i9,2(1x,i14),5(1x,f11.4),1x,i5,1x,i8,1x,a8,1x,f8.2,1x,i9,1x,a9,1x,i8,1x,f9.6)   
      go to 100
      
900   continue             
      stop

    end program add_util2
